package dao

import (
	"github.com/jinzhu/gorm"
	_ "github.com/jinzhu/gorm/dialects/mysql"
	"time"
)

var (
	DB *gorm.DB
)

func InitORM() {
	var (
		db  *gorm.DB
		err error
	)

	db, err = gorm.Open("mysql", "biz_user:finkauser000_@tcp(10.249.2.25:3306)/test_db?charset=utf8&parseTime=True&loc=Local")

	if err != nil {
		panic(err)
	}
	db.Set("gorm:table_options", "charset=utf8")
	db.DB().SetConnMaxLifetime(time.Second * 10)
	DB = db.Debug()
}

type Queue struct {
	ID        uint64    `json:"id" gorm:"primary_key"`
	CreatedAt time.Time `json:"create_at" gorm:"index;not null;default:CURRENT_TIMESTAMP"`
	UpdatedAt time.Time `json:"update_at" gorm:"not null;default:CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP"`

	Name       string `binding:"required" json:"name" gorm:"unique_index"`
	Describe   string `binding:"required" json:"desc" gorm:"column:description"`
	Password   string `binding:"required" json:"password"`
	TopicCount int    `json:"topics"`

	// operator
	Comment  string `binding:"required" json:"comment"`
	Operator string `json:"author"`
}
